$('#mdBtn').click(function () {
    var mdValue = txt.getValue();
    //var count = wordCount(mdValue);
    //console.log(mdValue + ', count ' + count);
    alert(mdValue);
});

$('#htmlBtn').click(function () {
    var htmlValue = txt.getHtml();
    alert(htmlValue);
});

$('#selectionBtn').click(function () {
    var selectText = txt.saveTextAreaSelection().text;
    alert(selectText);
});

$('#selectBtn').click(function () {
    txt.setTextAreaSelect(0, 3);
});


function wordCount(data) {
    var pattern = /[a-zA-Z0-9_\u0392-\u03c9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
    var m = data.match(pattern);
    var count = 0;
    if (m === null) {
        return count;
    }
    for (var i = 0; i < m.length; i++) {
        //console.log(m[i]);
        if (m[i].charCodeAt(0) >= 0x4E00) {
            count += m[i].length;
        } else {
            count += 1;
        }
    }
    return count;
}